<?php
//产品分类控制器
	namespace Application\Admin\Controller;
	use Application\Admin\Model\Procat as ProcatModel;
	class Procat extends Admin{
		public function index(){
		$cat = new ProcatModel();
		$this->cat = $cat -> order('id asc') -> select();
		$this -> render();
		}
		
		public function add(){
			if(IS_POST){
			if($_POST['cat_name'] == ''){
				echo "<script>alert('请输入信息');
					window.location.href='index.php?m=admin&c=procat&a=add';</script>";
				exit ;
			}				
				$cat = new ProcatModel();				
				$cat -> attributes -> name = $_POST['cat_name'];
				if($cat -> save()){
					echo "<script>alert('添加成功');
					window.location.href='index.php?m=admin&c=procat&a=index';</script>";
					exit;
				}
			}
			$this->render('add');
		}
		
		public function delete(){
			if(IS_GET){
				$id = $_GET['id'];
				$cat = new ProcatModel();
				$cat = $cat -> findModel($id);
				if($cat -> delete()){
					echo "<script>alert('删除成功');
					window.location.href='index.php?m=admin&c=procat&a=index';</script>";
				}
			}
		}				
		
		public function edit(){
			if(IS_GET){
				$id = $_GET['id'];
				$cat = new ProcatModel();
				$this->cat = $cat -> find($id);
				$this->render('edit');
			}
			if(IS_POST){
				$catModel = new ProcatModel();
				$id = $_POST['id'];
				$cat = $catModel->findModel($id);
				$cat -> attributes -> name = $_POST['cat_name'];

				if($cat -> save()){
					echo "<script>alert('编辑成功');
					window.location.href='index.php?m=admin&c=procat&a=index';</script>";
				}
			}
		}		
		
	}
?>